package com.example.qingyiapp.ui.activity.fragment.fragment_FrientUI.Adapter;

import android.content.Context;
import android.net.ConnectivityManager;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.example.qingyiapp.R;
import com.example.qingyiapp.ui.activity.fragment.fragment_FrientUI.Entify.Squareentify;
import com.example.qingyiapp.ui.activity.fragment.fragment_FrientUI.Interface.IOnClickListener;
import com.jcodecraeer.xrecyclerview.XRecyclerView;

import java.util.ArrayList;

/**
 * @author ：created by 申德丰
 * Create Date ：2019/9/17 16:18
 * Package_Name : QingYiApp
 */
public class friend_fragment_square_adapter extends XRecyclerView.Adapter<friend_fragment_square_adapter.MyViewHolde> {


    ArrayList<Squareentify> squareentifies;
    Context context;

    IOnClickListener iOnClickListener;

    public void setiOnClickListener(IOnClickListener iOnClickListener) {
        this.iOnClickListener = iOnClickListener;
    }

    public friend_fragment_square_adapter(ArrayList<Squareentify> squareentifies, Context context) {
        this.squareentifies = squareentifies;
        this.context = context;
    }

    @NonNull
    @Override
    public MyViewHolde onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {

        View inflate = LayoutInflater.from(context).inflate(R.layout.xrecyclerview_friend_square_item, viewGroup, false);
        return new MyViewHolde(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolde myViewHolde, final int i) {
        Squareentify squareentify = squareentifies.get(i);
        if(squareentify.getAttach_imgs().size()==0){
            Glide.with(context).load(squareentify.getPic()).into(myViewHolde.head);
            Log.d("#####判断", "进入判断1");
            myViewHolde.ll.setVisibility(View.VISIBLE);
            myViewHolde.re1.setVisibility(View.GONE);
            myViewHolde.re2.setVisibility(View.GONE);
            Glide.with(context).load(squareentify.getPic()).apply(RequestOptions.circleCropTransform()).into(myViewHolde.head2);
            Glide.with(context).load(squareentify.getPostcover1()).into(myViewHolde.left3);
            myViewHolde.address2.setText("旅行地："+squareentifies.get(i).getAddress());
            myViewHolde.name2.setText(squareentifies.get(i).getName());
            myViewHolde.time2.setText("时间："+squareentifies.get(i).getTime());
            myViewHolde.xq2.setText("详  情："+squareentifies.get(i).getXq());
            if(squareentifies.get(i).getXq().equals("")){
                myViewHolde.xq2.setVisibility(View.GONE);
            }
        }else if(squareentify.getAttach_imgs().size()==1){
            Glide.with(context).load(squareentify.getPic()).into(myViewHolde.head);
            Log.d("#####判断", "进入判断2");
            myViewHolde.re2.setVisibility(View.VISIBLE);
            myViewHolde.ll.setVisibility(View.GONE);
            myViewHolde.re1.setVisibility(View.GONE);
            Glide.with(context).load(squareentify.getPic()).apply(RequestOptions.circleCropTransform()).into(myViewHolde.head1);
            Glide.with(context).load(squareentify.getPostcover1()).into(myViewHolde.left1);
            Glide.with(context).load(squareentify.getAttach_imgs().get(0).toString()).into(myViewHolde.center2);

            myViewHolde.address1.setText("旅行地："+squareentifies.get(i).getAddress());
            myViewHolde.name1.setText(squareentifies.get(i).getName());
            myViewHolde.time1.setText("时间："+squareentifies.get(i).getTime());
            myViewHolde.xq1.setText("详  情："+squareentifies.get(i).getXq());
            if(squareentifies.get(i).getXq().equals("")){
                myViewHolde.xq1.setVisibility(View.GONE);
            }
        }else if(squareentify.getAttach_imgs().size()==2){
            Log.d("#####判断", "进入判断3");
            myViewHolde.re2.setVisibility(View.GONE);
            myViewHolde.ll.setVisibility(View.GONE);
            myViewHolde.re1.setVisibility(View.VISIBLE);


            Glide.with(context).load(squareentify.getPic()).into(myViewHolde.head);
            Glide.with(context).load(squareentify.getPic()).apply(RequestOptions.circleCropTransform()).into(myViewHolde.head);
            Glide.with(context).load(squareentify.getPostcover1()).into(myViewHolde.left);
            Glide.with(context).load(squareentify.getAttach_imgs().get(0).toString()).into(myViewHolde.center);
            Glide.with(context).load(squareentify.getAttach_imgs().get(1).toString()).into(myViewHolde.right);

            myViewHolde.address.setText("旅行地："+squareentifies.get(i).getAddress());
            myViewHolde.name.setText(squareentifies.get(i).getName());
            myViewHolde.time.setText("时间："+squareentifies.get(i).getTime());
            myViewHolde.xq.setText("详  情："+squareentifies.get(i).getXq());
            if(squareentifies.get(i).getXq().equals("")){
                myViewHolde.xq.setVisibility(View.GONE);
            }
        }

        myViewHolde.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                iOnClickListener.onxreviewitemonclick(i);
            }
        });


    }


    @Override
    public int getItemCount() {
        return squareentifies.size();
    }

    class MyViewHolde extends XRecyclerView.ViewHolder{


        RelativeLayout re1,re2;
        LinearLayout ll;

        ImageView head,left,center,right,left1,center2,left3,head1,head2;
        TextView name,address,time,xq;
        TextView name1,address1,time1,xq1;
        TextView name2,address2,time2,xq2;
        public MyViewHolde(@NonNull View itemView) {
            super(itemView);
            ll=itemView.findViewById(R.id.linner3);
            re1=itemView.findViewById(R.id.re1);
            re2=itemView.findViewById(R.id.re2);
            head=itemView.findViewById(R.id.image_tou);
            head1=itemView.findViewById(R.id.image_tou1);
            head2=itemView.findViewById(R.id.image_tou2);
            left=itemView.findViewById(R.id.leftimage);
            left1=itemView.findViewById(R.id.leftimage1);
            right=itemView.findViewById(R.id.rightimage);
            center=itemView.findViewById(R.id.centerimage);
            center2=itemView.findViewById(R.id.centerimage1);
            left3=itemView.findViewById(R.id.leftimage2);
            name=itemView.findViewById(R.id.text_name);
            address=itemView.findViewById(R.id.address);
            time=itemView.findViewById(R.id.time);
            xq=itemView.findViewById(R.id.xq);
            name1=itemView.findViewById(R.id.text_name1);
            address1=itemView.findViewById(R.id.address1);
            time1=itemView.findViewById(R.id.time1);
            xq1=itemView.findViewById(R.id.xq1);
            name2=itemView.findViewById(R.id.text_name2);
            address2=itemView.findViewById(R.id.address2);
            time2=itemView.findViewById(R.id.time2);
            xq2=itemView.findViewById(R.id.xq2);

        }
    }
}
